package com.cpj.bsyyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.DailyCare;
import com.cpj.bsyyzx.entity.ServicesFocus;
import com.cpj.bsyyzx.entity.User;
import com.cpj.bsyyzx.service.IDailyCareService;
import com.cpj.bsyyzx.service.IUserService;
import com.cpj.bsyyzx.util.CommonResult;
import lombok.extern.log4j.Log4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/dailyCare")
@Log4j
public class DailyCareController {

    @Resource
    IDailyCareService dailyCareService;

    @GetMapping("/list")
    @ResponseBody
    CommonResult  page(Page page, DailyCare dailyCare){

        QueryWrapper queryWrapper = new QueryWrapper();
        if(dailyCare!= null && StringUtils.isNotEmpty(dailyCare.getCustomerName())){
            queryWrapper.like("customer_name",dailyCare.getCustomerName());
        }
        return CommonResult.success(dailyCareService.page(page,queryWrapper));
    }
    @RequestMapping("save")
    @ResponseBody
        //将response 的 body响应
    CommonResult save(DailyCare dailyCare) {
        Map map = new HashMap();
        log.debug("保存");
        boolean success = dailyCareService.saveOrUpdate(dailyCare);

        return  CommonResult.success(success) ;
    }
    @RequestMapping("toedit")
    @ResponseBody
    CommonResult toedit(ModelMap modelMap, Integer id) {
        log.debug("跳转到修改页面");
//        User user = userService.getById(id);
//        modelMap.addAttribute("user", user);
        return CommonResult.success(dailyCareService.getById(id));
    }
    @RequestMapping("delete/{id}")
    @ResponseBody
    CommonResult delete(@PathVariable Integer id) {
        log.debug("bbb根据主键删除:" + id);
        boolean success = dailyCareService.removeById(id);
        return CommonResult.success(success);
    }

}
